param(
	[Parameter(Mandatory=$true)]
	[string]$DC
)
$array = @()
$DC=$DC+'.domain.internal'
Clear-Content .\AllADGroups.csv
$AllGroups = get-adgroup -Server $DC -Filter *
foreach($group in $AllGroups){
	$grpinfo = Get-ADGroup -Server $DC -Identity $group  -Properties *
	$Properties = @{`
		"SamAccountName" = $grpinfo.SamAccountName;`
		"Name" = $grpinfo.Name;`
		"GroupScope"=$grpinfo.GroupScope;`
		"GroupCategory"=$grpinfo.GroupCategory;`
		"Description"=$grpinfo.Description;`
		"When Created" = "+"+$grpinfo.whenCreated.ToString("MM/dd/yyyy HH:mm:ss");`
		"Modified" = "+"+$grpinfo.Modified.ToString("MM/dd/yyyy HH:mm:ss");`
		"DistinguishedName"=$grpinfo.DistinguishedName;`
		"ManagedBy"=$grpinfo.ManagedBy;
	}
	$Newobject = New-Object  PSObject -Property  $Properties
	$Array +=$Newobject
}
$Array | Select-Object `
	"SamAccountName",`
	"Name",`
	"GroupScope",`
	"GroupCategory",`
	"Description",`
	"When Created",`
	"Modified",`
	"DistinguishedName",`
	"ManagedBy" `
| Export-CSV .\AllADGroups.csv -UseCulture -NoTypeInformation -Encoding UTF8
Send-MailMessage `
	-from "xxxx" `
	-to "xxx" `
	-subject "AllADGroups" `
	-Attachments .\AllADGroups.csv `
	-smtpserver xxxx `
	-Encoding ([System.Text.Encoding]::UTF8)
